/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package hxg.portmgr.core.line;

import hxg.portmgr.core.device.Device;
import hxg.portmgr.core.device.intf.Intf;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import hxg.portmgr.core.dao.LineDAO;
import hxg.portmgr.core.dao.DaoSource;

/**
 *
 * @author hxg
 */
public class Line {

    long id;
    String name;
    LinkedHashSet<Intf> connectedIntfs = new LinkedHashSet();
    LinkedHashSet<String> connectedNodes = new LinkedHashSet();
    LinkedList<Line> subLineList = new LinkedList();

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public String toString() {
        return name;
    }
    
    public LinkedHashSet<Intf> getIntfs(){
        return connectedIntfs;
    }
    
    public void disConnectToIntf(Intf inf){
        connectedIntfs.remove(inf);
    }
    
    public void disConnectToNode(String node){
        connectedNodes.remove(node);
    }

    public Line ConnectToIntf(Intf inf) {
        connectedIntfs.add(inf);
        return this;
    }

    public Line ConnectToNode(String node) {
        connectedNodes.add(node);
        return this;
    }

    public LinkedHashSet<String> getConnectNodes() {
        return connectedNodes;
    }

    public LinkedHashSet<Device> getConnectDevices() {
        LinkedHashSet<Device> devs = new LinkedHashSet();
        for (Intf inf : connectedIntfs) {
            devs.add(inf.getDevice());
        }
        return devs;
    }
    
    public static Line connectIntfs(Intf inf1,Intf inf2){
        return DaoSource.getLineDao().connect(inf1, inf2);
    }
}
